package fr.web325.servlet.admin.order;

import fr.web325.bean.Order;
import fr.web325.dao.OrderDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.sql.SQLException;

@WebServlet("/shop/modifyOrder2")
public class ModifyOrder2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取表单数据
        String id = req.getParameter("id");
        String receiverAddress = req.getParameter("receiverAddress");
        String receiverPhone = req.getParameter("receiverPhone");
        String receiverName = req.getParameter("receiverName");
        String paystate = req.getParameter("paystate");
        String user_id = req.getParameter("user_id");
        Order order = new Order(id,new Date(),receiverName,receiverAddress,receiverPhone,10.40,Integer.parseInt(paystate),Integer.parseInt(user_id));
        try {
            if (new OrderDao().editOrder(order)) {
                // 重定向
                resp.sendRedirect("admin/order");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
